package com.foodorder.entity;

import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 退款实体类
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Entity
@Table(name = "refunds")
@EntityListeners(AuditingEntityListener.class)
public class Refund {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    /**
     * 订单ID
     */
    @Column(nullable = false)
    private Long orderId;
    
    /**
     * 订单号
     */
    @Column(nullable = false, length = 32)
    private String orderNo;
    
    /**
     * 用户ID
     */
    @Column(nullable = false)
    private Long userId;
    
    /**
     * 店铺ID
     */
    @Column(nullable = false)
    private Long storeId;
    
    /**
     * 退款金额
     */
    @Column(nullable = false, precision = 10, scale = 2)
    private BigDecimal refundAmount;
    
    /**
     * 原订单金额
     */
    @Column(nullable = false, precision = 10, scale = 2)
    private BigDecimal originalAmount;
    
    /**
     * 退款原因
     */
    @Column(nullable = false, length = 500)
    private String reason;
    
    /**
     * 退款状态
     */
    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    private RefundStatus status = RefundStatus.PENDING;
    
    /**
     * 退款类型
     */
    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    private RefundType refundType;
    
    /**
     * 管理员备注
     */
    @Column(length = 500)
    private String adminRemark;
    
    /**
     * 操作员ID
     */
    private Long operatorId;
    
    /**
     * 支付交易ID（用于退款）
     */
    @Column(length = 100)
    private String paymentTransactionId;
    
    /**
     * 退款交易ID
     */
    @Column(length = 100)
    private String refundTransactionId;
    
    /**
     * 申请时间
     */
    @CreatedDate
    @Column(nullable = false, updatable = false)
    private LocalDateTime createdAt;
    
    /**
     * 更新时间
     */
    @LastModifiedDate
    @Column(nullable = false)
    private LocalDateTime updatedAt;
    
    /**
     * 审核时间
     */
    private LocalDateTime reviewedAt;
    
    /**
     * 退款完成时间
     */
    private LocalDateTime refundedAt;
    
    /**
     * 退款状态枚举
     */
    public enum RefundStatus {
        PENDING,    // 待审核
        PROCESSING, // 处理中
        COMPLETED,  // 已完成
        REJECTED,   // 已拒绝
        FAILED,     // 失败
        CANCELLED   // 已取消
    }
    
    /**
     * 退款类型枚举
     */
    public enum RefundType {
        FULL,    // 全额退款
        PARTIAL  // 部分退款
    }
    
    // Explicit getter and setter methods
    public Long getId() {
        return id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    public Long getOrderId() {
        return orderId;
    }
    
    public void setOrderId(Long orderId) {
        this.orderId = orderId;
    }
    
    public String getOrderNo() {
        return orderNo;
    }
    
    public void setOrderNo(String orderNo) {
        this.orderNo = orderNo;
    }
    
    public Long getUserId() {
        return userId;
    }
    
    public void setUserId(Long userId) {
        this.userId = userId;
    }
    
    public Long getStoreId() {
        return storeId;
    }
    
    public void setStoreId(Long storeId) {
        this.storeId = storeId;
    }
    
    public BigDecimal getRefundAmount() {
        return refundAmount;
    }
    
    public void setRefundAmount(BigDecimal refundAmount) {
        this.refundAmount = refundAmount;
    }
    
    public BigDecimal getOriginalAmount() {
        return originalAmount;
    }
    
    public void setOriginalAmount(BigDecimal originalAmount) {
        this.originalAmount = originalAmount;
    }
    
    public String getReason() {
        return reason;
    }
    
    public void setReason(String reason) {
        this.reason = reason;
    }
    
    public RefundStatus getStatus() {
        return status;
    }
    
    public void setStatus(RefundStatus status) {
        this.status = status;
    }
    
    public RefundType getRefundType() {
        return refundType;
    }
    
    public void setRefundType(RefundType refundType) {
        this.refundType = refundType;
    }
    
    public String getAdminRemark() {
        return adminRemark;
    }
    
    public void setAdminRemark(String adminRemark) {
        this.adminRemark = adminRemark;
    }
    
    public Long getOperatorId() {
        return operatorId;
    }
    
    public void setOperatorId(Long operatorId) {
        this.operatorId = operatorId;
    }
    
    public LocalDateTime getCreatedAt() {
        return createdAt;
    }
    
    public void setCreatedAt(LocalDateTime createdAt) {
        this.createdAt = createdAt;
    }
    
    public LocalDateTime getUpdatedAt() {
        return updatedAt;
    }
    
    public void setUpdatedAt(LocalDateTime updatedAt) {
        this.updatedAt = updatedAt;
    }
    
    public LocalDateTime getReviewedAt() {
        return reviewedAt;
    }
    
    public void setReviewedAt(LocalDateTime reviewedAt) {
        this.reviewedAt = reviewedAt;
    }
    
    public LocalDateTime getRefundedAt() {
        return refundedAt;
    }
    
    public void setRefundedAt(LocalDateTime refundedAt) {
        this.refundedAt = refundedAt;
    }
} 